using AutoMapper;
using UwinEducation.Application.Dtos.Orders;
using UwinEducation.Domain.Entities;

namespace UwinEducation.Application.Mappings
{
    /// <summary>
    /// 订单折扣映射配置
    /// </summary>
    public class OrderDiscountProfile : Profile
    {
        /// <summary>
        /// 构造函数，配置映射关系
        /// </summary>
        public OrderDiscountProfile()
        {
            // 实体到DTO的映射
            CreateMap<OrderDiscount, OrderDiscountDto>()
                .ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Creator.RealName))
                .ForMember(dest => dest.OrderNumber, opt => opt.MapFrom(src => src.Order != null ? src.Order.OrderNumber : null));

            // 创建DTO到实体的映射
            CreateMap<CreateOrderDiscountDto, OrderDiscount>();

            // 更新DTO到实体的映射(仅映射需要更新的字段)
            CreateMap<UpdateOrderDiscountDto, OrderDiscount>()
                .ForMember(dest => dest.CreatedAt, opt => opt.Ignore())
                .ForMember(dest => dest.OrderId, opt => opt.Ignore())
                .ForMember(dest => dest.Order, opt => opt.Ignore());
        }
    }
} 